package com.grass.p019lv.novel.fragment;

import android.content.Intent;
import android.graphics.Color;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
import androidx.recyclerview.widget.GridLayoutManager;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import com.androidsa.bttsddka.R;
import com.androidx.p013lv.base.bean.UserInfo;
import com.androidx.p013lv.base.bean.novel.FictionBean;
import com.androidx.p013lv.base.bean.novel.FictionList;
import com.androidx.p013lv.base.bean.novel.LabelFictionData;
import com.androidx.p013lv.base.bean.request.ReqLabelFiction;
import com.androidx.p013lv.base.dialog.BuyVipDialog;
import com.androidx.p013lv.base.dialog.ProgressBarDialog;
import com.androidx.p013lv.base.http.BaseRes;
import com.androidx.p013lv.base.http.HttpUtils;
import com.androidx.p013lv.base.http.JsonParams;
import com.androidx.p013lv.base.http.UrlManager;
import com.androidx.p013lv.base.http.callback.HttpCallback;
import com.androidx.p013lv.base.interfaces.Key;
import com.androidx.p013lv.base.listener.ItemClickListener;
import com.androidx.p013lv.base.p015ui.LazyFragment;
import com.androidx.p013lv.base.utils.NetUtil;
import com.androidx.p013lv.base.utils.SpUtils;
import com.androidx.p013lv.invention.adapter.AdapterFictionLabel;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.listener.OnItemClickListener;
import com.google.gson.Gson;
import com.grass.p019lv.databinding.FragmentClassFictionBinding;
import com.grass.p019lv.novel.activity.NovelActivity;
import com.grass.p019lv.novel.adapter.FictionAdapter;
import com.scwang.smartrefresh.layout.api.RefreshLayout;
import com.scwang.smartrefresh.layout.listener.OnRefreshLoadMoreListener;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;

/* renamed from: com.grass.lv.novel.fragment.FictionLabelFragment */
public class FictionLabelFragment extends LazyFragment<FragmentClassFictionBinding> implements ItemClickListener, OnRefreshLoadMoreListener, View.OnClickListener {
    private AdapterFictionLabel adapterLabel;
    FictionAdapter adapterLabelVideoTwo;
    private int classifyId;
    private int editMax;
    private int fictionSpace = 0;
    private int fictionType = 1;
    private View headerView;
    List<Integer> integerList = new ArrayList();
    private boolean isFirst = true;
    List<LabelFictionData> labelData;
    private ProgressBarDialog loading;
    private boolean mIsShowOnly = true;
    private List<FictionList> mList = new ArrayList();
    private int orderType = 1;
    private int page = 1;
    private int pageSize = 30;
    private RecyclerView rv_label;
    private TextView tv_hot;
    private TextView tv_like;
    private TextView tv_long_p;
    private TextView tv_new;
    private TextView tv_open;
    private TextView tv_short_p;

    @Override // com.androidx.p013lv.base.p015ui.LazyFragment
    public int setFragmentView() {
        return R.layout.fragment_class_fiction;
    }

    static /* synthetic */ int access$108(FictionLabelFragment fictionLabelFragment) {
        int i = fictionLabelFragment.editMax;
        fictionLabelFragment.editMax = i + 1;
        return i;
    }

    static /* synthetic */ int access$110(FictionLabelFragment fictionLabelFragment) {
        int i = fictionLabelFragment.editMax;
        fictionLabelFragment.editMax = i - 1;
        return i;
    }

    public static FictionLabelFragment newInstance(int i, List<LabelFictionData> list) {
        Bundle bundle = new Bundle();
        bundle.putSerializable("classifyId", Integer.valueOf(i));
        bundle.putSerializable("tagList", (Serializable) list);
        FictionLabelFragment fictionLabelFragment = new FictionLabelFragment();
        fictionLabelFragment.setArguments(bundle);
        return fictionLabelFragment;
    }

    @Override // androidx.fragment.app.Fragment
    public void setArguments(Bundle bundle) {
        super.setArguments(bundle);
        if (bundle != null) {
            this.classifyId = bundle.getInt("classifyId");
            this.labelData = (List) bundle.getSerializable("tagList");
        }
    }

    @Override // com.androidx.p013lv.base.p015ui.LazyFragment
    public void initViews() {
        ProgressBarDialog progressBarDialog = new ProgressBarDialog(getActivity());
        this.loading = progressBarDialog;
        progressBarDialog.setHint("拚命載入中...");
        ((FragmentClassFictionBinding) this.binding).refresh.setOnRefreshListener(this);
        ((FragmentClassFictionBinding) this.binding).refresh.setOnLoadMoreListener(this);
        ((FragmentClassFictionBinding) this.binding).recycler.setLayoutManager(new LinearLayoutManager(getActivity()));
        FictionAdapter fictionAdapter = new FictionAdapter();
        this.adapterLabelVideoTwo = fictionAdapter;
        fictionAdapter.addChildClickViewIds(R.id.retry_view, R.id.ll_root);
        View inflate = LayoutInflater.from(getActivity()).inflate(R.layout.fragment_fiction_lable_header, (ViewGroup) null);
        this.headerView = inflate;
        this.adapterLabelVideoTwo.addHeaderView(inflate);
        ((FragmentClassFictionBinding) this.binding).recycler.setAdapter(this.adapterLabelVideoTwo);
        this.adapterLabelVideoTwo.setOnItemClickListener(new OnItemClickListener() {
            /* class com.grass.p019lv.novel.fragment.FictionLabelFragment.C31841 */

            @Override // com.chad.library.adapter.base.listener.OnItemClickListener
            public void onItemClick(BaseQuickAdapter<?, ?> baseQuickAdapter, View view, int i) {
                if (!FictionLabelFragment.this.isOnClick()) {
                    if (SpUtils.getInstance().getUserInfo().getFreeWatches() != -1) {
                        new BuyVipDialog(FictionLabelFragment.this.getContext()).show();
                        return;
                    }
                    FictionList fictionList = (FictionList) baseQuickAdapter.getItem(i);
                    if (fictionList.getFictionId() > 0) {
                        int fictionId = fictionList.getFictionId();
                        Intent intent = new Intent(FictionLabelFragment.this.getActivity(), NovelActivity.class);
                        intent.putExtra(Key.NOVEL_ID, fictionId);
                        FictionLabelFragment.this.getActivity().startActivity(intent);
                    }
                }
            }
        });
        this.adapterLabel = new AdapterFictionLabel();
        this.rv_label = (RecyclerView) this.headerView.findViewById(R.id.rv_label);
        GridLayoutManager gridLayoutManager = new GridLayoutManager(getActivity(), 4);
        gridLayoutManager.setSmoothScrollbarEnabled(true);
        gridLayoutManager.setAutoMeasureEnabled(true);
        this.rv_label.setLayoutManager(gridLayoutManager);
        this.rv_label.setNestedScrollingEnabled(false);
        this.rv_label.setAdapter(this.adapterLabel);
        this.adapterLabel.setItemListener(new ItemClickListener() {
            /* class com.grass.p019lv.novel.fragment.FictionLabelFragment.C31852 */

            @Override // com.androidx.p013lv.base.listener.ItemClickListener
            public void onItemClick(View view, int i) {
                int tagId;
                if (!FictionLabelFragment.this.isOnClick()) {
                    if (((LabelFictionData) FictionLabelFragment.this.adapterLabel.getDataInPosition(i)).getStatus() == 0) {
                        FictionLabelFragment.access$108(FictionLabelFragment.this);
                    } else {
                        FictionLabelFragment.access$110(FictionLabelFragment.this);
                    }
                    if (FictionLabelFragment.this.editMax > 5) {
                        FictionLabelFragment.access$110(FictionLabelFragment.this);
                        return;
                    }
                    ((LabelFictionData) FictionLabelFragment.this.adapterLabel.getDataInPosition(i)).setStatus(((LabelFictionData) FictionLabelFragment.this.adapterLabel.getDataInPosition(i)).getStatus() == 0 ? 1 : 0);
                    FictionLabelFragment.this.adapterLabel.notifyDataSetChanged();
                    List data = FictionLabelFragment.this.adapterLabel.getData();
                    FictionLabelFragment.this.integerList.clear();
                    for (int i2 = 0; i2 < data.size(); i2++) {
                        if (1 == ((LabelFictionData) FictionLabelFragment.this.adapterLabel.getDataInPosition(i2)).getStatus() && (tagId = ((LabelFictionData) data.get(i2)).getTagId()) != 0) {
                            FictionLabelFragment.this.integerList.add(Integer.valueOf(tagId));
                        }
                    }
                    FictionLabelFragment.this.page = 1;
                    FictionLabelFragment.this.getInfo();
                }
            }
        });
        getLabel();
        getInfo();
        this.tv_open = (TextView) this.headerView.findViewById(R.id.tv_open);
        this.tv_new = (TextView) this.headerView.findViewById(R.id.tv_new);
        this.tv_hot = (TextView) this.headerView.findViewById(R.id.tv_hot);
        this.tv_like = (TextView) this.headerView.findViewById(R.id.tv_more_like);
        this.tv_long_p = (TextView) this.headerView.findViewById(R.id.tv_long_p);
        this.tv_short_p = (TextView) this.headerView.findViewById(R.id.tv_short_p);
        this.headerView.findViewById(R.id.tv_open).setOnClickListener(this);
        this.headerView.findViewById(R.id.tv_new).setOnClickListener(this);
        this.headerView.findViewById(R.id.tv_hot).setOnClickListener(this);
        this.headerView.findViewById(R.id.tv_more_like).setOnClickListener(this);
        this.headerView.findViewById(R.id.tv_long_p).setOnClickListener(this);
        this.headerView.findViewById(R.id.tv_short_p).setOnClickListener(this);
        ((FragmentClassFictionBinding) this.binding).statusLayout.setOnRetryListener(new View.OnClickListener() {
            /* class com.grass.p019lv.novel.fragment.FictionLabelFragment.View$OnClickListenerC31863 */

            public void onClick(View view) {
                FictionLabelFragment.this.page = 1;
                FictionLabelFragment.this.getInfo();
            }
        });
    }

    /* access modifiers changed from: package-private */
    public void getLabel() {
        List<LabelFictionData> list = this.labelData;
        if (list != null && list.size() > 10) {
            this.adapterLabel.setShowOnlyFour(this.mIsShowOnly);
        }
        this.adapterLabel.setData(this.labelData);
        this.adapterLabel.notifyDataSetChanged();
        getInfo();
    }

    /* access modifiers changed from: package-private */
    public void getInfo() {
        ((FragmentClassFictionBinding) this.binding).recycler.setVisibility(0);
        if (NetUtil.isNetworkAvailable()) {
            if (this.isFirst) {
                this.isFirst = false;
            } else {
                this.loading.show();
            }
            ReqLabelFiction reqLabelFiction = new ReqLabelFiction();
            reqLabelFiction.setClassId(this.classifyId);
            reqLabelFiction.setFictionSpace(this.fictionSpace);
            reqLabelFiction.setFictionType(1);
            reqLabelFiction.setOrderType(this.orderType);
            reqLabelFiction.setTagIds(this.integerList);
            reqLabelFiction.setPage(this.page);
            reqLabelFiction.setPageSize(30);
            String json = new Gson().toJson(reqLabelFiction);
            HttpUtils.getInsatance().post(UrlManager.getInsatance().postFictionFindList(), json, new HttpCallback<BaseRes<FictionBean>>("postFictionFindList") {
                /* class com.grass.p019lv.novel.fragment.FictionLabelFragment.C31874 */

                public void onLvSuccess(BaseRes<FictionBean> baseRes) {
                    if (FictionLabelFragment.this.loading != null && FictionLabelFragment.this.loading.isShowing()) {
                        FictionLabelFragment.this.loading.dismiss();
                    }
                    if (FictionLabelFragment.this.binding != null && FictionLabelFragment.this.getActivity() != null) {
                        ((FragmentClassFictionBinding) FictionLabelFragment.this.binding).refresh.finishRefresh();
                        ((FragmentClassFictionBinding) FictionLabelFragment.this.binding).refresh.finishLoadMore();
                        if (baseRes.getCode() == 200) {
                            if (baseRes.getData() != null && baseRes.getData().getData() != null && baseRes.getData().getData().size() > 0) {
                                FictionLabelFragment.this.mList = baseRes.getData().getData();
                                if (FictionLabelFragment.this.page == 1) {
                                    FictionLabelFragment.this.adapterLabelVideoTwo.setNewInstance(FictionLabelFragment.this.mList);
                                    return;
                                }
                                ((FragmentClassFictionBinding) FictionLabelFragment.this.binding).refresh.resetNoMoreData();
                                FictionLabelFragment.this.adapterLabelVideoTwo.addData((Collection) baseRes.getData().getData());
                            } else if (FictionLabelFragment.this.page == 1) {
                                FictionLabelFragment.this.mList.clear();
                                FictionLabelFragment.this.mList.add(new FictionList(true));
                                FictionLabelFragment.this.adapterLabelVideoTwo.setNewInstance(FictionLabelFragment.this.mList);
                                FictionLabelFragment.this.adapterLabelVideoTwo.notifyDataSetChanged();
                                ((FragmentClassFictionBinding) FictionLabelFragment.this.binding).refresh.finishLoadMoreWithNoMoreData();
                            } else {
                                ((FragmentClassFictionBinding) FictionLabelFragment.this.binding).refresh.finishLoadMoreWithNoMoreData();
                            }
                        } else if (FictionLabelFragment.this.page == 1) {
                            FictionLabelFragment.this.mList.clear();
                            FictionLabelFragment.this.mList.add(new FictionList(true));
                            FictionLabelFragment.this.adapterLabelVideoTwo.setNewInstance(FictionLabelFragment.this.mList);
                            FictionLabelFragment.this.adapterLabelVideoTwo.notifyDataSetChanged();
                            ((FragmentClassFictionBinding) FictionLabelFragment.this.binding).refresh.finishLoadMoreWithNoMoreData();
                        }
                    }
                }
            });
        }
    }

    @Override // androidx.fragment.app.Fragment, com.gyf.immersionbar.components.ImmersionFragment
    public void onResume() {
        super.onResume();
        getUserInfo();
    }

    public void getUserInfo() {
        HttpUtils.getInsatance().post(UrlManager.getInsatance().userInfo(), JsonParams.build().commit(), new HttpCallback<BaseRes<UserInfo>>("userInfo") {
            /* class com.grass.p019lv.novel.fragment.FictionLabelFragment.C31885 */

            public void onLvSuccess(BaseRes<UserInfo> baseRes) {
                if (baseRes.getCode() == 200) {
                    SpUtils.getInstance().setUserInfo(baseRes.getData());
                }
            }
        });
    }

    @Override // com.androidx.p013lv.base.listener.ItemClickListener
    public void onItemClick(View view, int i) {
        if (!isOnClick() && view.getId() == R.id.retry_view) {
            this.page = 1;
            this.loading.show();
            getInfo();
        }
    }

    public void onClick(View view) {
        if (!isOnClick()) {
            if (view.getId() == R.id.tv_new) {
                this.tv_new.setBackgroundResource(R.drawable.shape_fiction_label_select);
                this.tv_hot.setBackgroundResource(0);
                this.tv_like.setBackgroundResource(0);
                this.tv_new.setTextColor(Color.parseColor("#FFCEEF"));
                this.tv_hot.setTextColor(Color.parseColor("#FFFFFF"));
                this.tv_like.setTextColor(Color.parseColor("#FFFFFF"));
                this.orderType = 1;
                getInfo();
            }
            if (view.getId() == R.id.tv_hot) {
                this.tv_new.setBackgroundResource(0);
                this.tv_hot.setBackgroundResource(R.drawable.shape_fiction_label_select);
                this.tv_like.setBackgroundResource(0);
                this.tv_new.setTextColor(Color.parseColor("#FFFFFF"));
                this.tv_hot.setTextColor(Color.parseColor("#FFCEEF"));
                this.tv_like.setTextColor(Color.parseColor("#FFFFFF"));
                this.orderType = 2;
                getInfo();
            }
            if (view.getId() == R.id.tv_more_like) {
                this.tv_new.setBackgroundResource(0);
                this.tv_hot.setBackgroundResource(0);
                this.tv_like.setBackgroundResource(R.drawable.shape_fiction_label_select);
                this.tv_new.setTextColor(Color.parseColor("#FFFFFF"));
                this.tv_hot.setTextColor(Color.parseColor("#FFFFFF"));
                this.tv_like.setTextColor(Color.parseColor("#FFCEEF"));
                this.orderType = 3;
                getInfo();
            }
            if (view.getId() == R.id.tv_long_p) {
                this.tv_long_p.setBackgroundResource(R.drawable.shape_fiction_label_select);
                this.tv_short_p.setBackgroundResource(0);
                this.tv_long_p.setTextColor(Color.parseColor("#FFCEEF"));
                this.tv_short_p.setTextColor(Color.parseColor("#FFFFFF"));
                this.fictionSpace = 1;
                getInfo();
            }
            if (view.getId() == R.id.tv_short_p) {
                this.tv_long_p.setBackgroundResource(0);
                this.tv_short_p.setBackgroundResource(R.drawable.shape_fiction_label_select);
                this.tv_long_p.setTextColor(Color.parseColor("#FFFFFF"));
                this.tv_short_p.setTextColor(Color.parseColor("#FFCEEF"));
                this.fictionSpace = 2;
                getInfo();
            }
        }
    }

    @Override // com.scwang.smartrefresh.layout.listener.OnLoadMoreListener
    public void onLoadMore(RefreshLayout refreshLayout) {
        this.page++;
        getInfo();
    }

    @Override // com.scwang.smartrefresh.layout.listener.OnRefreshListener
    public void onRefresh(RefreshLayout refreshLayout) {
        this.page = 1;
        getInfo();
    }

    @Override // androidx.fragment.app.Fragment, com.androidx.p013lv.base.p015ui.LazyFragment
    public void onDestroyView() {
        super.onDestroyView();
    }

    @Override // androidx.fragment.app.Fragment, com.gyf.immersionbar.components.ImmersionFragment
    public void onDestroy() {
        super.onDestroy();
        HttpUtils.getInsatance().cancelTag("postFictionFindList");
        HttpUtils.getInsatance().cancelTag("userInfo");
    }
}
